package com.youlai.system.common.manager;


import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 异步任务管理器
 *
 * @author sc
 */
public class AsyncManager {


    /**
     * 异步操作任务调度线程池
     */
    private ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();

    /**
     * 单例模式
     */
    private AsyncManager() {
    }

    private static AsyncManager me = new AsyncManager();

    public static AsyncManager me() {
        return me;
    }

    /**
     * 执行任务
     *
     * @param task 任务
     */
    public void submit(TimerTask task) {
        executor.submit(task);
    }

    public void execute(Runnable runnable) {
        executor.execute(runnable);
    }

    /**
     * 停止任务线程池
     */
    public void shutdown() {
        executor.shutdown();
    }
}
